<template>
	<view>
		<u-tabbar :value="value1" @change="change">
			<u-tabbar-item :text="item.label" v-for="(item,key) in tabbars" :key="key">
				<template #inactive-icon>
					<view :class="[item.icon]"></view>
				</template>
				<template #active-icon>
					<view :class="[item.icon]"></view>
				</template>
			</u-tabbar-item>

		</u-tabbar>
	</view>
</template>

<script>
	export default {
		name: "ztabbar",
		data() {
			return {
				value1: "",

			};
		},
		computed: {

			tabbars() {
				let r = [{
					icon: "iconfont iconicon-chongdianzhuang",
					url: "/pages/index/index",
					label: "首页"
				}, {
					icon: "iconfont iconquyu",
					url: "/pages/Station/Station",
					label: "站点"
				}, {
					icon: "iconfont icontixian ",
					url: "/pages/revenue/revenue",
					label: "收入"
				}, {
					icon: "iconfont iconicon-gerenzhongxin-xuanzhong ",
					url: "/pages/home/home",
					label: "个人中心"
				}]
				if (r[this.value1]) {
					r[this.value1].icon = r[this.value1].icon + " active"
				}

				return r
			}
		},
		mounted() {
			this.init()
		},
		methods: {
			init() {
				let curPage = getCurrentPages();
				let route = curPage[curPage.length - 1].route; //获取当前页面的路

				let i = this.tabbars.findIndex(e => {
					return e.url && e.url.includes(route)
				})
				this.value1 = i
			},
			change(v) {
				uni.reLaunch({
					url: this.tabbars[v].url
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.u-tabbar-item__icon {
		.iconfont {
			width: 48rpx;
			height: 48rpx;
			display: flex;
			justify-content: center;
			align-items: center;
			font-size: 48rpx;
			position: relative;
			top: -4rpx;
			color: rgb(125, 126, 128);

			&.active {
				color: $uni-color-primary;
			}
		}
	}

	.z-tabbar__content__circle__borde {
		width: 100rpx;
		height: 100rpx;
		border: 1px solid #dadbde;
		position: absolute;
		top: -50%;
		left: 50%;
		z-index: -10;
		transform: translateX(-50%);
		border-radius: 50%;
		background: #fff;
	}

	.tabbarsys {
		width: 140rpx;
		height: 140rpx;
		border: 1px solid #dadbde;
		position: absolute;
		top: -100rpx;
		border-radius: 50%;
		background-color: #fff;

		.text {
			width: 100rpx;
			height: 100rpx;
			background-color: $u-primary;
			border-radius: 50%;
			position: absolute;
			left: 50%;
			transform: translateX(-50%);
			top: 20rpx;
			display: flex;
			align-items: center;
			justify-content: center;
			color: #fff;
			font-size: 40rpx;
		}

		// left: 50%;
		&::before {
			content: "";
			width: 144rpx;
			height: 140rpx;
			background-color: #fff;
			position: absolute;
			left: -2rpx;
			bottom: 0;
			// z-index: -1;
			top: 50rpx
		}
	}
</style>